package edu.bit.water.service;

import edu.bit.water.dao.WasteWaterDao;
import edu.bit.water.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WasteWaterService {
    @Autowired
    private WasteWaterDao wasteWaterDao;

    public List<WasteWaterTable1> table1Select(int lastId) {
        return wasteWaterDao.table1Select(lastId);
    }
    public List<WasteWaterTable2> table2Select(int lastId) {
        return wasteWaterDao.table2Select(lastId);
    }


    public List<MetaBaseline> getMetaData(String stdNumber) {
        return wasteWaterDao.getMetaData(stdNumber);
    }
    public List<WasteWaterTable2> getTable2Data(String lastId) {
        return wasteWaterDao.getTable2Data(lastId);
    }

    public List<WasteWaterTable1> getTable1Data(String lastId) {
        return wasteWaterDao.getTable1Data(lastId);
    }
    public void table1Insert(WasteWaterTable1 wasteWaterTable1)
    {
        wasteWaterDao.table1Insert(wasteWaterTable1);
    }
    public void table2Insert(WasteWaterTable2 wasteWaterTable2)
    {
//        System.out.println(wasteWaterTable2.getTotalAmount());
//        System.out.println(wasteWaterTable2.getPosition());
//        System.out.println(wasteWaterTable2.getLastId());
//        System.out.println(wasteWaterTable2.getNote());
        wasteWaterDao.table2Insert(wasteWaterTable2);
    }

    public void delete(List<Integer> ids) {
        for (Integer id : ids) {
            wasteWaterDao.delete(id);
        }
    }

    public void table1update(WasteWaterTable1 wasteWaterTable1) {
        wasteWaterDao.table1update(wasteWaterTable1);
    }
    public void table2update(WasteWaterTable2 wasteWaterTable2) {
        wasteWaterDao.table2update(wasteWaterTable2);
    }

    public Map<String, String> labelUpdate(WasteWaterEva wasteWaterEva) {
        Map<String, String> modelMap = new HashMap<>();

            int n = wasteWaterDao.labelUpdate(wasteWaterEva);
            if (n == 1)
                modelMap.put("status", "success");
            else
                modelMap.put("status", "failed");
            return modelMap;


    }

}
